package exam.fourParadigm.S2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static int m;
    public static int n;
    public static char[][] graph;
    public static int[][] result;
    public static int[] dx = new int[] {-1, 1, 0, 0};
    public static int[] dy = new int[] {0, 0, -1, 1};
    public static int num;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        m = sc.nextInt();
        n = sc.nextInt();
        sc.nextLine();
        graph = new char[m][n];
        result = new int[m][n];
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        for (int i = 0; i < 4; i++) {
            String s = br.readLine();
//            String s = sc.nextLine();
//            graph[i] = s.toCharArray();
            System.out.println(s + " ====");
        }
        solution();
        for (int i=0; i<m; ++i) {
            for (int j = 0; j < n; j++) {
                if (result[i][j] == 0)
                    System.out.print(".");
                else
                    System.out.print(result[i][j] % 10);
            }
            System.out.println();
        }
    }

    private static void solution() {
        boolean[][] vis = new boolean[m][n];
        for (int i=0; i<m; ++i) {
            for (int j = 0; j < n; j++) {
                if (graph[i][j] == '*') {
                    num = 0;
                    graph[i][j] = '.';
                    dfs(i, j, vis);
                    clear(i, j, vis);
                    graph[i][j] = '*';
                    result[i][j] = num;
                }
            }
        }
    }

    private static void dfs(int x, int y, boolean[][] vis) {
        vis[x][y] = true;
        num++;
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 || nx >= m || ny < 0 || ny >= n || vis[nx][ny] || graph[nx][ny] == '*')
                continue;
            dfs(nx, ny, vis);
        }
    }

    private static void clear(int x, int y, boolean[][] vis) {
        vis[x][y] = false;
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 || nx >= m || ny < 0 || ny >= n || !vis[nx][ny] || graph[nx][ny] == '*')
                continue;
            clear(nx, ny, vis);
        }
    }
}